package com.mt.api.modules.controller;

import com.mt.api.modules.domain.bo.AppBossAddBo;
import com.mt.api.modules.domain.bo.AppBossEditInfoBo;
import com.mt.api.modules.domain.bo.BossDelBo;
import com.mt.api.modules.domain.bo.BossInfoBo;
import com.mt.api.modules.domain.vo.AppBossInfoVo;
import com.mt.api.modules.domain.vo.AppBossVo;
import com.mt.api.modules.service.IBossService;
import com.mt.api.util.ParamsValid;
import com.mt.common.response.WebResponse;
import com.mt.common.response.WebResponseUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * @author plover
 * @date 2020-07-06
 **/
@RestController
@RequiredArgsConstructor
@Api(tags = "账号管理")
@RequestMapping("/app/boss")
public class AppBossController {

    private final IBossService bossService;

    @GetMapping("/list")
    public WebResponse getBossList() {
        return bossService.getBossList();
    }

    @PostMapping("/add")
    @ApiOperation(value = "", notes = "添加子账号", httpMethod = "GET")
    public WebResponse addBoss(@RequestBody AppBossAddBo bo) {
        ParamsValid valid = new ParamsValid();
        valid.validNotNull("手机号不能为空", bo.getPhone());
        if (!valid.isValid()) {
            return WebResponseUtils.errorParam(valid.getMsg());
        }
        return bossService.addBoss(bo);
    }

    @PostMapping("/editInfo")
    @ApiOperation(value = "", notes = "修改账号信息", httpMethod = "GET")
    public WebResponse editInfo(@RequestBody AppBossEditInfoBo bo) {
        ParamsValid valid = new ParamsValid();
        valid.validNotNull("id不能为空", bo.getId());
        if (!valid.isValid()) {
            return WebResponseUtils.errorParam(valid.getMsg());
        }
        return bossService.editInfo(bo);
    }

    @PostMapping("/edit")
    @ApiOperation(value = "", notes = "修改子账号", httpMethod = "GET")
    public WebResponse editBoss(@RequestBody AppBossAddBo bo) {
        ParamsValid valid = new ParamsValid();
        valid.validNotNull("手机号不能为空", bo.getPhone())
                .validNotNull("id不能为空", bo.getId());
        if (!valid.isValid()) {
            return WebResponseUtils.errorParam(valid.getMsg());
        }
        return bossService.editBoss(bo);
    }

    @GetMapping("/detail")
    public WebResponse<AppBossVo> bossDetail(Integer id) {
        ParamsValid valid = new ParamsValid();
        valid.validNotNull("id不能为空", id);
        if (!valid.isValid()) {
            return WebResponseUtils.errorParam(valid.getMsg());
        }
        return bossService.bossDetail(id);
    }

    @PostMapping("/del")
    public WebResponse delBoss(@RequestBody BossDelBo bo) {
        ParamsValid valid = new ParamsValid();
        valid.validNotNull("id不能为空", bo.getId());
        if (!valid.isValid()) {
            return WebResponseUtils.errorParam(valid.getMsg());
        }
        return bossService.delBoss(bo);
    }

    @GetMapping("/brand")
    @ApiOperation(value = "", notes = "获取账号品牌信息", httpMethod = "GET")
    public WebResponse bossBrand() {
        return bossService.bossBrand();
    }

    @GetMapping("/getAccountTypeList")
    @ApiOperation(value = "", notes = "获取账号类型枚举", httpMethod = "GET")
    public WebResponse getAccountTypeList() {
        return bossService.getAccountTypeList();
    }

    @GetMapping("/info")
    @ApiOperation(value = "", notes = "账号详情信息接口", httpMethod = "GET")
    public WebResponse<AppBossInfoVo> bossInfo(BossInfoBo bo) {
        return bossService.bossInfo(bo);
    }

}